package com.wkm.myapplication.vp

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

/**
 * TODO 简要描述
 * @author chaochaowu @ Zebra Inc.
 * @since 12-27-2021
 */
class MyViewPager @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : ViewPager(context, attrs) {

    var initX = 0F
    var initY = 0F

    override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
        event ?: return false
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                initX = event.x
                initY = event.y
                Log.e("TAG", "down ${event.x},${event.y}")
            }
            MotionEvent.ACTION_MOVE -> {
                Log.e("TAG", "move ${event.x},${event.y}")
                val deltaX = Math.abs(event.x - initX)
                val deltaY = Math.abs(event.x - initY)
                if (deltaX > 20) {
                    return true
                }
            }
            MotionEvent.ACTION_CANCEL -> {

            }
        }
        return super.onInterceptTouchEvent(event)
    }
}


